package filter;

import java.util.ArrayList;

import models.Post;

/**
 * Dato un titolo, cerca tutti i post che lo contengono.
 */
public class FilterPostsByTitle implements IFilterPosts {

	private final String title;

	public FilterPostsByTitle(String title) {
		if (title == null) {
			this.title = "";
		} else {
			this.title = title;
		}
	}

	@Override
	public ArrayList<Post> applyFilter(ArrayList<Post> postList) {
		final ArrayList<Post> resultPostList = new ArrayList<Post>();

		for (final Post post : postList) {
			if (post.getTitle().toLowerCase().contains(title.toLowerCase())) {
				resultPostList.add(post);
			}
		}

		return resultPostList;
	}

}
